<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ExportHelpPages.php 377 2010-09-10 08:14:28Z steen.rabol $
 *
 */

class ExportHelpPages extends PortalAdminPage
{
	public static function ToolMenuName()
	{
		return Prado::localize('Export help pages');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->PageTitle = "Export help pages";
		if(!$this->Page->IsPostBack)
		{
			$this->LanguageList->PromptText	= Prado::localize('Select');
			$this->LanguageList->PromptValue	= "0";
			$this->LanguageList->DataSource	= $this->DataAccess->createCommand("select name,culture from tbllanguages where active=1 order by name")->query();
			$this->LanguageList->dataBind();
		}
	}

	public function ExportPages()
	{
		if($this->IsValid)
		{
			$culture	= $this->LanguageList->SelectedValue;

			$doc		= new TXmlDocument('1.0','utf-8');
			$doc->TagName='pradoportalhelppages';

	 		$proc	= new TXmlElement('helppages');
	 		$proc->setAttribute('culture',$culture);
	 		$doc->Elements[]=$proc;

	 		$lstrings	= $this->DataAccess->createCommand("select pagename, title, content from tblhelp where culture='$culture'")->query();
	 		$id			= 0;

	 		foreach($lstrings as $lstring)
	 		{
	 			$query				= new TXmlElement('helppage');
	 			$query->setAttribute('id',++$id);
	 			$proc->Elements[]	= $query;

	 			$attr				= new TXmlElement('pagename');
	 			$attr->Value		= $lstring['pagename'];
	 			$query->Elements[]	= $attr;

	 			$attr				= new TXmlElement('title');
	 			$attr->Value		= $lstring['title'];
	 			$query->Elements[]	= $attr;

				$attr				= new TXmlElement('content');
	 			$attr->Value		= $lstring['content'];
	 			$query->Elements[]	= $attr;

			}

			PortalUtil::CreateDirStructure($this->Application->PortalBasePath	. '/storage/tmp');
			$this->Response->clear();
			$xmlFileName	= $this->Application->PortalBasePath	. '/storage/tmp/help_' . $culture . ".xml";
			$doc->saveToFile($xmlFileName);
			$this->Response->writeFile($xmlFileName);
			exit();
		}
	}
}

?>